//
// Created by liushuai on 2020/4/1.
//
#include "maxSubArray.h"
int maxSubArray(vector<int>& nums) {
    if(nums.size()==0)
        return 0;
    else{
        int current = nums.at(0);
        int sum = nums.at(0);
        for(int index=1;index<nums.size();index++){
            if(current<0)
                current=nums[index];//所有元素全为负数则返回最大值
            else
                current+=nums.at(index);
            if(current>sum)
                sum = current;
        }
        return sum;
    }

}
